perm filename SMERGE.MAC[S,AIL] blob sn#229784 filedate 1976-08-05 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00047 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00005 00002	TITLE SMERGE - MERGE OF SEVERAL SOURCES
C00007 00003	COMMAND FILE THINGS
C00009 00004		DEFINE MAKIO (INSTR,ADR)
C00011 00005	ERROR ROUTINES
C00012 00006	STPT:	SKIPA
C00015 00007	MEOFM:	MOVEI CHAN,1
C00017 00008	MEOFMS:	MOVSI CHAN,-3	GEN EOFS ON ALL CHANNELS
C00018 00009	NMTCH:	SETZM MPOS
C00021 00010	MULLPP:	MOVSI T4,-3	TRY ALL THREE CHANNELS
C00023 00011	SET USE FLAG
C00025 00012	TRY02:	MOVEI CHAN,2
C00026 00013	ALLEOF:	MOVSI CHAN,-3	EOF ON ALL CHANELS LOOKING FOR MATCH
C00028 00014	FINAL:	SKIPN T1,CNFNUM
C00029 00015	TXTSRC:	PUSHJ P,SKPSP	NOW SCAN THE COMMAND
C00031 00016		DEFINE COMANDS
C00033 00017	CHKXIT:	TRNN FL,F.RDTM
C00034 00018	MERGE:	SKIPN FILNAM+2
C00036 00019	F1DON:	MOVE T1,1(T5)	GET FILE USE BACK
C00038 00020	F1DCON:	MOVSI CHAN,-3
C00040 00021		DEFINE COMANDS
C00042 00022	CRSPRN:	PUSHJ P,WTLF
C00044 00023	CRSCLR:	PUSHJ P,WTLF
C00046 00024	CRSGO:	PUSHJ P,WTLF
C00048 00025	THIS ROUTINE SETS UP THE INFORMATION NECESSARY TO PUT OUT A LINE
C00050 00026	HERE IF SECONDARY ALSO SEQUENCED
C00052 00027	OUTLIN:	TLNE FL,F.SEQ	SEQUENCED?
C00054 00028	GENSEQ:	MOVE T1,LNMOUT
C00056 00029	SEQPOK:	TLNE FL,F.SMOD
C00057 00030	DIFPRN:	TRNE FL,F.ABRT
C00059 00031	DIFPR1:	AOS CHAN,DIFFIL
C00060 00032	PRTCON:	TRNN FL,F.ABRT		NO CONFLICTS IF ABORTING
C00062 00033	PRINT A CONFLICT
C00064 00034	GET THE NEXT LINE. NON-SKIP RETURN IF NO NEXT LINE
C00066 00035	OUTDEC:	IDIVI T1,↑D10
C00068 00036	UUODCF:	MOVEI C,"0"
C00069 00037	GENERATE LIST POINTERS FOR A CHANEL
C00071 00038	INRLN1:	AOBJN T4,INRLP
C00073 00039	POSITION TO A LINE USING ORG
C00075 00040	FIND A LINE IN THE LINE TABLE LIST. NUMBER IN T1
C00078 00041	REMOVE A LINE BLOCK FROM LIST AND PUT ON FREE CORE
C00079 00042	RDFLNM:	SETZM FILNAM+1
C00082 00043		DEFINE COMANDS
C00084 00044	RDUSRN:	MOVE T1,[POINT 6,FILNAM+4]
C00085 00045	READ A LINE FROM APPROPRIATE CHANNEL AND RETURN HASH AND ORG
C00087 00046	GNCLNM:	MOVE LINUM,@1(BUF)
C00089 00047	ROUTINE TO GET A CHARACTER AND WORRY ABOUT BLANK LINES
C00092 ENDMK
C⊗;
TITLE SMERGE - MERGE OF SEVERAL SOURCES

P=17	;PDL
LINUM=16	;LINE NUMBER (PAGE NUM LH. LINE NUMBER (BIN) RH)
C=15		;CHARACTER
CHAN=14		;CHANNEL IN USE
BUF=13		;POINTER TO BUFFERS IN USE
ORG=12		;LINE ORIGIN (LH COUNT, RH BLOCK)
HASH=10		;HASH OF LINE
HASH1=11	;MUST BE A PAIR FOR DMOVE
LNS1=7	;REAL LINE NUMBERS

FL=0		;FLAG REGISTER
 F.BLIN==1	;IGNORE BLANK LINES
 F.COM==2	;IGNORE COMMENTS (AFTER ;)
 F.MULT==4	;TREAT MULTIPLE BLANKS (TABS) AS SINGLE BLANK
 F.LSTL==10	;LAST LINE WHEN PRINTING
 F.NLST==20	;NEED ONE EXTRA LINE
 F.SWTC==40	;LOOK FOR SWITCHES AFTER FILE NAME
 F.RDTM==100	;READ FROM COMMAND FILE
 F.TMOP==200	;COMMAND FILE OPEN EVEN IF NOT READING NOW
 F.ABRT==400	;DOING AN ABORT, GET FILES RENAMED

;LEFT HELF

 F.SEQ==1	;OUTPUT IS TO BE SEQUENCED
 F.SMOD==2	;OUTPUT SEQ TO BE MODIFIED
 F.SGEN==4	;GENERATE SEQ NUMBER
 F.LPG==10	;GENERATE A PAGE MARK AT END
 F.PPAG==20	;PRIMARY FILE IS PAGES (SETSEQ)
 F.SSEQ==40	;SECONDARY SOURCE IS SEQUENCED (SETSEQ)

T1=1
T2=2
T3=3
T4=4
T5=5

MAXCHN==3	;NUMBER OF CHANNELS
FSTCHN==1	;FIRST CHANNEL TO USE
OUTCHN==FSTCHN+MAXCHN	;OUTPUT CHANNEL
CMDCHN==OUTCHN+1	;COMMAND CHANNEL

EXTERNL JOBFF,JOBREL

JOBVER==137
INTERNAL JOBVER
	LOC JOBVER
	4
	RELOC
;COMMAND FILE THINGS

RPGOPN:	RESET
	OPEN CMDCHN,CMDOPN
	 JRST STPT	;CAN NOT GET IT, LOSE BIG
	PJOB T1,
	IDIVI T1,↑D100
	ADDI T1,'0'
	DPB T1,[POINT 6,CMDFIL+2,5]
	MOVE T1,T2
	IDIVI T1,↑D10
	ADDI T1,'0'
	DPB T1,[POINT 6,CMDFIL+2,11]
	ADDI T2,'0'
	DPB T2,[POINT 6,CMDFIL+2,17]
	MOVE T2,CMDFIL+2
	MOVEM T2,CMDFIL
	MOVE T2,CMDFIL+1
	EXCH T2,CMDFIL+3
	MOVEM T2,CMDFIL+1
	LOOKUP CMDCHN,CMDFIL
	 JRST STPT	;NOT THERE
	MOVEI FL,F.RDTM!F.TMOP!F.SWTC
	JRST REGO	;THE CONTINUE POINT

CMDCHR:	TRNN FL,F.RDTM	;FROM TEMP FILE?
	JRST	[INCHWL C
		POPJ P,]	;NO
	SOSG CMDBUF+2
	IN CMDCHN,0
	JRST	[ILDB C,CMDBUF+1
		JUMPE C,CMDCHR
		OUTCHR C	;DUPLEX IT
		POPJ P,]
	RENAME CMDCHN,[0]	;GET RID OF COMMAND FILE
	 JFCL
	EXIT		;AND DONE
	DEFINE MAKIO (INSTR,ADR)
<ZZQ==FSTCHN
	REPEAT MAXCHN,<MAKIO1 (INSTR,\ZZQ,ADR)
ZZQ==ZZQ+1>>

	DEFINE MAKIO1 (INSTR,CHN,ADR)
<	INSTR CHN,ADR>

ARRAY EOF,BLOCKN,PAGNUM,NUMLNS,LNKHED,LNKEND[MAXCHN],PDL[40]
ARRAY CRSLNS[MAXCHN],CMDBUF[3]

INP:	MAKIO (INPUT,0)
EOFTST:	MAKIO (STATO,20000)


ARRAY BUFS[MAXCHN*3],SHS1,SHASH[2],MPOS,MPS,MPSP[MAXCHN],OBUF[3]

ZZQ==0
BUFORG:	REPEAT MAXCHN,<BUFS+ZZQ
ZZQ==ZZQ+3>

FILASK:	[ASCIZ /
MASTER FILE/]
	[ASCIZ /
PRIMARY EDIT/]
	[ASCIZ /
SECONDARY EDIT/]

OPN:	MAKIO (OPEN,OPNBLK)
LOKP:	MAKIO (LOOKUP,FILNAM)

OPNBLK:	0
	SIXBIT /DSK/
	0

FILNAM:	3
	BLOCK 5

USI:	MAKIO (USETI,(ORG))

ARRAY PAGLN,REALN,LSTLNC[MAXCHN]

BLKSIZ==6	;SIZE OF CORE BLOCK
;ERROR ROUTINES

BADFIL:	OUTSTR @FILASK(CHAN)
	OUTSTR [ASCIZ / BAD FILE
/]
	EXIT

NOFIL:	OUTSTR [ASCIZ /
CAN NOT FIND FILE/]
	POPJ P,

NODSK:	OUTSTR [ASCIZ /
CAN NOT INIT DISK/]
	EXIT

CORERR:	OUTSTR [ASCIZ /
INSUFFICIENT CORE/]
	EXIT

	DEFINE UNDEF (A)
<IRP A,<A:	OUTSTR [ASCIZ /
A UNDEFINED/]
	EXIT>>		;FOR UNDEFINED LABELS


	LOC 41
	JSR UUOH
	RELOC

OPDEF ODEC [1B8]
OPDEF ODECF [2B8]
OPDEF OCRI [3B8]
OPDEF OSTR [4B8]

CMDOPN:	0
	SIXBIT /DSK/
	CMDBUF

CMDFIL:	3
	0
	'SMG'
	SIXBIT /TMP/

DEATH:	OUTSTR [ASCIZ /
SMERGE FROM COMMAND FILE WITH STRANGE ERROR
FILES NOT CLEANED UP/]
	EXIT
STPT:	SKIPA
	JRST RPGOPN
	RESET
	MOVEI FL,F.SWTC
REGO:	MOVEI T1,3
	MOVEM T1,XTRMTC#	;NUMBER OF EXTRA LINES TO MATCH
	MOVE P,[IOWD 40,PDL]
	MOVSI CHAN,-MAXCHN
OPNLP:	MOVE T1,BUFORG(CHAN)
	MOVEM T1,OPNBLK+2
	XCT OPN(CHAN)
	 JRST NODSK
ASKFIL:	OUTSTR @FILASK(CHAN)
	OUTSTR [ASCIZ /: /]
	PUSHJ P,RDFLNM
	TRNN FL,F.ABRT	;IS THIS PART OF AN ABORT?
	JRST ASKNAB	;NO
	HRRZ T1,CHAN
	CAIE T1,1
	JRST ABTASK	;LOOKUP ONLY FOR PRIMARY EDIT
ASKNAB:	MOVE T1,FILNAM+2
	MOVEM T1,FILNAM
	MOVE T1,FILNAM+1
	EXCH T1,FILNAM+3
	MOVEM T1,FILNAM+1
	XCT LOKP(CHAN)		;DO THE LOOKUP
	JRST	[PUSHJ P,NOFIL
		TRNE FL,F.RDTM
		JRST DEATH	;LOSE BIG
		JRST ASKFIL]
	SETZM EOF(CHAN)
	MOVEI T1,1
	MOVEM T1,PAGNUM(CHAN)
	SETZM PAGLN(CHAN)
	SETZM REALN(CHAN)
	SETZM BLOCKN(CHAN)
	SETZM LNKHED(CHAN)
	SETZM NUMLNS(CHAN)
	MOVEI T1,LNKHED(CHAN)
	MOVEM T1,LNKEND(CHAN)
	SETZM LSTLNC(CHAN)
ABTASK:	AOBJN CHAN,OPNLP
	TRZ FL,F.SWTC	;NO MORE SWITCHES
	TRNE FL,F.ABRT
	JRST CMDLP	;STRAIGHT TO COMMAND LOOP
	SETZM FRECOR#
	SETZM CHGLNK#
	MOVEI T1,CHGLNK
	MOVEM T1,ELNK#
	SETZM CNFNUM#
MAIN:	MOVSI CHAN,-3		;MAKE SURE ALL FILES HAVE A LINE
MAIN1:	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST @EOFTAB(CHAN)
	AOBJN CHAN,MAIN1
	DMOVEM HASH,SHASH	;SAVE HASH FOR COMPARISON
	MOVSI CHAN,-2	;NOW COMPARE
MAIN2:	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST PRGERR	;IT WAS THERE BEFORE
	CAMN HASH,SHASH
	CAME HASH1,SHASH+1
	JRST NMTCH	;LINE DOES NOT MATCH
	AOBJN CHAN,MAIN2
	MOVSI CHAN,-3	;NOW DUMP ALL THOSE LINES
MAIN3:	MOVEI T1,1
	PUSHJ P,DMPLIN
	AOBJN CHAN,MAIN3
	JRST MAIN

EOFTAB:	MEOFM		;EOF ON MASTER
	MEOFP		;EOF ON PRIMARY
	MEOFS		;EOF ON SECONDARY
MEOFM:	MOVEI CHAN,1
	MOVEI T1,1	;CHECK FOR OTHER EOF'S
	PUSHJ P,FNDLIN
	 JRST MEOFMP	;EOF ON MASTER AND PRIMARY
	MOVEI CHAN,2
	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST MEOFMS	;EOF ON MASTER AND SECONDARY
MEOFS:	MOVSI CHAN,-3	;NEED TO READ ALL TO EOF
MEOFS1:	SETZM USEFLG
MEOFS2:	AOS T1,USEFLG	;THE LINE TO READ
	PUSHJ P,FNDLIN
	 JRST MEOFS3	;FILLAY FOUND EOF
	JRST MEOFS2	;NEXT LINE

MEOFS3:	PUSHJ P,GENEOF	;PUT AN EOF MARKER IN
	AOBJN CHAN,MEOFS1	;NEXT CHANNEL
	JRST NMTCH	;CAN ONLY MATCH ON THE EOFS

MEOFP:	MOVEI CHAN,2
	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST FINAL	;EOF ON PRIMARY AND SEONDARY, END
	JRST MEOFS	;READ ALL TO EOF AND COMPARE
MEOFMS:	MOVSI CHAN,-3	;GEN EOFS ON ALL CHANNELS
MEOFMC:	PUSHJ P,GENEOF
	SETOM EOF(CHAN)
	AOBJN CHAN,MEOFMC
	MOVE T1,[NUMLNS,,MPOS]
	BLT T1,MPOS+2
	JRST MTCFN1

MEOFMP:	MOVEI CHAN,2
	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST FINAL	;EOF ON ALL
	JRST MEOFMS	;END EOF FLAGS ON ALL AND SET POINTERS
NMTCH:	SETZM MPOS
	SETZM MPOS+1
	SETZM MPOS+2	;MPOS RECORDS THE NUMBER OF LINE HERE
NMTCH0:	MOVSI CHAN,-3
NMTCH1:	AOS T1,MPOS(CHAN)
	PUSHJ P,FNDLIN
	 XCT EOFTB2(CHAN)	;GET NEXT LINE
NMTCH2:	AOBJN CHAN,NMTCH1
	MOVSI T5,-3	;NOW TRY COMPARES, 3 ORDERINGS
INRC:	MOVE CHAN,CHANTB(T5)	;GET CHANNEL
	SKIPN T1,MPOS(CHAN)	;USE ONLY LAST LINE
	JRST NXTINR		;FORGET IT IF NO LINE
	MOVEM T1,MPS
	PUSHJ P,FNDLIN
	 JRST PRGERR	;IT WAS THERE
	DMOVEM HASH,SHASH
	MOVE CHAN,CHANTB+1(T5)	;NOW CHECK ALL LINES ON 2ND
	MOVN T4,MPOS(CHAN)
	JUMPE T4,NXTINR	;THIS CAN NOT MATCH
	HRLZS T4		;THIS GETS THE NUMBER AS AOBJN PTR
INRLP:	MOVEI T1,1(T4)
	PUSHJ P,FNDLIN
	 JRST PRGERR
	CAMN HASH,SHASH
	CAME HASH1,SHASH+1
	JRST INRLN1		;NO MATCH
	MOVEI T1,1(T4)
	MOVEM T1,MPS+1	;SAVE LINE NUMBER
	PUSH P,T4	;SAVE T4 (WITH COUNT)
	MOVE CHAN,CHANTB+2(T5)	;NOW 3RD
	MOVN T4,MPOS(CHAN)
	JUMPE T4,[SETZM MPS+2
		JRST INRLP3]	;NOW TRY THE MULTI LINE MATCH
	HRLZS T4
	SETZM INFLG#
INRLP2:	MOVEI T1,1(T4)
	PUSHJ P,FNDLIN
	 JRST PRGERR
	CAMN HASH,SHASH
	CAME HASH1,SHASH+1
	JRST INRLN2	;NO MATCH
	MOVEI T1,1(T4)
	MOVEM T1,MPS+2
INRLP3:	SETOM INFLG	;MATCH SEEN ON FILE 3
	PUSH P,T4	;NOW CHECK FOR CORRECT NUMBER OF MATCHES
	SKIPN T4,XTRMTC	;NUMBER OF EXTRA LINES TO MATCH
	JRST MTCFND	;NONE, FOUND
	MOVEM T4,XTRMNM#	;SAVE COUNT
	MOVE T1,[MPS,,MPSP]
	BLT T1,MPSP+2
MULLPP:	MOVSI T4,-3	;TRY ALL THREE CHANNELS
MULLPT:	MOVE CHAN,@CHNPTR(T4)
	SKIPN MPSP(T4)
	JRST MULLPA		;ASSUME MATCH IF NOT THERE
	AOS T1,MPSP(T4)	;NEXT LINE
	PUSHJ P,FNDLIN
	 XCT EOFTB3(T4)
	XCT LIMMTC(T4)	;POSSIBLY SAVE HASH
	CAMN HASH,SHS1	;WILL WORK FIRST TIME, HASH JUST SAVED
	CAME HASH1,SHS1+1
	JRST TRIABT	;NO MATCH, GIVE UP THIS SET
MULLPA:	AOBJN T4,MULLPT	;TRY ALL CHANNELS
	SOSLE XTRMNM
	JRST MULLPP	;NEXT SET OF LINES
MTCFND:	POP P,T4
	POP P,T4
	MOVSI T4,-3
ORDMPS:	MOVE CHAN,@CHNPTR(T4)	;NOW SET ENDING NUMBERS
	MOVE T1,MPS(T4)
	MOVEM T1,MPOS(CHAN)
	JUMPE T1,[PUSHJ P,GENEOF	;GET AN EOF IF NEEDED
		AOS MPOS(CHAN)
		JRST .+1]
	AOBJN T4,ORDMPS
MTCFN1:	PUSHJ P,GETCOR	;GET A CORE BLOCK FOR THE DIF INFO
	SETZM (T2)	;NO LINK
	MOVE T5,T2	;SAVE IT
	MOVSI CHAN,-3
LSTGEN:	PUSHJ P,GENCHN	;GENERATE INFORMATION
	MOVEM T4,2(T5)	;LINK IT IN
	ADDI T5,1
	AOBJN CHAN,LSTGEN
	SUBI T5,3
	MOVE T1,PAGE1#	;SAVE LINES OF FIRST PAGE FOR CH 2
	MOVEM T1,5(T5)
;SET USE FLAG

	MOVEI CHAN,0
	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST PRGERR
	DMOVEM HASH,SHASH
	MOVEI CHAN,1
	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST PRGERR
	CAMN HASH,SHASH
	CAME HASH1,SHASH+1
	JRST TRY02	;0 AND 1 DO NOT MATCH, TRY 0 AND 2
	MOVEI T4,0
CHKUSE:	MOVE CHAN,CHKTAB(T4)
	MOVE T1,MPOS(CHAN)
	MOVE CHAN,CHKTAB+1(T4)
	CAME T1,MPOS(CHAN)
	JRST USE3		;NUMBERS DO NOT MATCH, CONFLICT
	MOVEI T1,1
	MOVEM T1,USEFLG
CHKUSL:	MOVE CHAN,CHKTAB(T4)
	AOS T1,USEFLG
	CAML T1,MPOS(CHAN)
	JRST SETUSE	;AT END, WE KNOW WHICH TO USE
	PUSHJ P,FNDLIN
	 JRST PRGERR
	DMOVEM HASH,SHASH
	MOVE CHAN,CHKTAB+1(T4)
	MOVE T1,USEFLG
	PUSHJ P,FNDLIN
	 JRST PRGERR
	CAMN HASH,SHASH
	CAME HASH1,SHASH+1
	JRST USE3	;NO MATCH, CONFLICT
	JRST CHKUSL

USE3:	MOVEI T1,3
	AOS CNFNUM	;COUNT CONFLICT
DMPIT:	JUMPE T1,ABTLNK	;THIS IS SET IF 1 AND 2 MATCH
	MOVEM T1,1(T5)
	HRRM T5,@ELNK	;LINK THE CHANGE BLOCK INTO LIST
	HRRZM T5,ELNK
DMPIT1:	MOVSI CHAN,-3
CHNDMP:	MOVE T1,MPOS(CHAN)
	PUSHJ P,DMPLIN
	AOBJN CHAN,CHNDMP
	JRST MAIN	;CONTINUE SCANNING

SETUSE:	MOVE T1,CHKTAB+2(T4)
	JRST DMPIT	;THIS IS THE ONE TO USE
TRY02:	MOVEI CHAN,2
	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST PRGERR
	CAMN HASH,SHASH
	CAME HASH1,SHASH+1
	JRST TRY12	;NO MATCH, TRY 1 AND 2
	MOVEI T4,3
	JRST CHKUSE

TRY12:	DMOVEM HASH,SHASH
	MOVEI CHAN,1
	MOVEI T1,1
	PUSHJ P,FNDLIN
	 JRST PRGERR
	CAMN HASH,SHASH
	CAME HASH1,SHASH+1
	JRST USE3	;NO MATCH HERE EITHER, CONFLICT
	MOVEI T4,6
	JRST CHKUSE

CHKTAB:	OCT 0,1,2,0,2,1,1,2,0

ABTLNK:	DMOVE T1,2(T5)
	HRRZM T1,(T2)	;RELINK THE CORE BLOCKS
	MOVE T3,4(T5)
	HRRZM T2,(T3)
	HRRZM T3,(T5)
	EXCH T5,FRECOR
	MOVEM T5,(T1)
	JRST DMPIT1
ALLEOF:	MOVSI CHAN,-3	;EOF ON ALL CHANELS LOOKING FOR MATCH
ALLEF1:	PUSHJ P,GENEOF	;ENERATE A BLOCK FOR THE END OF FILE
	AOS MPOS(CHAN)	;COUNT IT
	AOBJN CHAN,ALLEF1
	JRST MTCFN1	;AND GO

GENEOF:	PUSHJ P,GETCOR
	SETZM (T2)
	SETZM 1(T2)	;NO HASH ON EOF
	SETZM 2(T2)
	SETOM 3(T2)	;ORG TO AN INPOSSIBLE NUMBER
	SKIPN LSTLNC(CHAN)	;DOES THIS ONE HAVE NUMBERS?
	JRST EOFGU	;NO
	HRLZ T1,REALN(CHAN)
	MOVEM T1,5(T2)	;SET AS IF WE JUST SAW A PAGE MARK
	AOS T1,PAGNUM(CHAN)
	HRLZM T1,4(T2)	;AS PAGE NUMBER
EOFGC:	HRRM T2,@LNKEND(CHAN)
	HRRZM T2,LNKEND(CHAN)	;LINK IT IN
	AOS NUMLNS(CHAN)
	POPJ P,

EOFGU:	SETZM 4(T2)	;FOR UN-NUMBEREED, NO LINE NUMBER
	AOS T1,REALN(CHAN)	;AND 1 MORE LINE
	MOVEM T1,5(T2)
	JRST EOFGC	;NOW GO LINK
FINAL:	SKIPN T1,CNFNUM
	JRST NOCNF	;SAY NO CONFLICTS
	OUTSTR [ASCIZ /
/]
	PUSHJ P,OUTDEC	;PRINT THE NUMBER OF CONFLICTS
	MOVE T1,CNFNUM
	CAIE T1,1
	OUTSTR [ASCIZ / CONFLICTS
/]
	CAIN T1,1
	OUTSTR [ASCIZ / CONFLICT
/]
	JRST CMDLP

NOCNF:	OUTSTR [ASCIZ /
NO CONFLICTS
/]
CMDLP:	OUTSTR [ASCIZ /*/]
	MOVE T5,[-CMDLEN,,CMDNAM]
	PUSHJ P,TXTSRC	;SEARCH TABLE AFTER READING TEXT
	 JRST CMDLP	;NOTHING THERE
	 JRST ILLCMD	;AMBIGUOUS OR NOT FOUND
	SUBI T5,CMDNAM
	XCT CMDDSP(T5)	;GO

ILLCMD:	OUTSTR [ASCIZ /TYPE HELP FOR HELP
/]
	TRNN FL,F.RDTM
	JRST CMDLP
	JRST DEATH

TXTSRC:	PUSHJ P,SKPSP	;NOW SCAN THE COMMAND
	MOVE T1,[POINT 6,ACCUM]
	MOVEI T2,6
	SETZM ACCUM#
	PUSHJ P,RDTXT1	;READ COMMAND
	TRNN FL,F.SWTC	;IN CASE WE ARE REALLY SCANNING SWITCH OR CONFLICT COMMAND
	PUSHJ P,RDFLNM	;POSSIBLE FILE NAME THERE
	SKIPN T1,ACCUM
	POPJ P,		;NOTHING THERE
	AOS (P)		;EITHER BAD RETURN OR GOOD RETURN NOW
	MOVEI T2,0
	MOVSI T3,770000
GENMSK:	TDNE T1,T3
	IOR T2,T3
	LSH T3,-6
	JUMPN T3,GENMSK	;GENERATE A MASK FOR COMMAND
	MOVEI T4,0
CMDSRC:	CAMN T1,(T5)	;T5 HAS AOBJN POINTER TO TABLE
	JRST CPOPJ1	;FOUND A MATCH
	MOVE T3,(T5)
	AND T3,T2
	CAME T3,T1
	JRST CMDSR1
	JUMPN T4,CPOPJ	;MULTIPLE PARTIAL MATCH
	MOVE T4,T5
CMDSR1:	AOBJN T5,CMDSRC
	SKIPE T5,T4
	AOS (P)		;FOUND COMMAND
	POPJ P,		;OR NOT
	DEFINE COMANDS
<	X HELP,<JRST HELP>
	X CONFLICTS,<JRST PRTCON>
	X MERGE,<JRST MERGE>
	X DIFFERENCES,<JRST DIFPRN>
	X QUIT,<JRST CHKXIT>
>

	DEFINE MAKCMD (TL)
<	DEFINE X (A,B)
<	<SIXBIT /A/>>

TL'NAM:	COMANDS
TL'LEN==.-TL'NAM

	DEFINE X (A,B)
<	B>

TL'DSP:	COMANDS
>

	MAKCMD (CMD)

HELP:	OUTSTR HLPMS
	JRST CMDLP

HLPMS:	ASCIZ /
COMMANDS ARE:

HELP		PRINT THIS MESSAGE

QUIT		RETURN TO MONITOR

CONFLICTS	PRINT ALL CONFLICTS (MAY BE FOLLOWED BY FILE NAME)

DIFFERENCES	PRINT A SOURCE COMPARE AS IT WOULD BE BETWEEN
		THE PRIMARY EDIT FILE AND A FILE GENERATED BY
		THE MERGE COMMAND (MAY BE FOLLOWED BY FILE NAME)

MERGE		GENERATE THE MERGED OUTPUT FILE (MUST BE FOLLOWED
		BY A FILE NAME)

/
CHKXIT:	TRNN FL,F.RDTM
	EXIT
	ANDI FL,F.RDTM!F.ABRT!F.TMOP
	JRST REGO	;START WITH THE NEXT ONE
MERGE:	SKIPN FILNAM+2
	JRST NEDFIL	;WE NEED A FILE NAME
	TRNE FL,F.ABRT
	JRST MRGABT	;JUST RENAME FILE
	PUSHJ P,OPNOUT
	 JRST CMDLP	;CAN NOT OPEN
	USETI FSTCHN+1,1
	MOVEI T1,1
	MOVEM T1,OUTPAG#
	MOVEM T1,PAGNUM+1
	SETZM BLOCKN+1
	SETZM EOF+1
	TLZ FL,F.SEQ!F.SMOD!F.SGEN!F.LPG	;CLEARE FLAGS
	SKIPE LSTLNC+1
	TLO FL,F.SEQ	;OUTPUT SHOULD BE SEQUENCED
	SETZM LNMOUT#
	SETOM LNROUT#		;REAL NUMBER OUTPUT FOR ORDER ERROR CHECK
	SETZM CFONUM	;ZERO CONFLICT NUMBER
	SKIPN T5,CHGLNK
	JRST TOEOF1	;COPY 1 TO EOF, WE ARE AT END
MRGLP:	MOVE T1,1(T5)
	CAIGE T1,2
	JRST MRGNXT	;IGNORE THIS ONE (0 OR 1)
	MOVE T4,3(T5)
	MOVE ORG,(T4)
	MOVEM ORG,ORGEND	;COPY TO HERE
	TRZ FL,F.LSTL!F.NLST
	MOVEI CHAN,1
MRGCP1:	PUSHJ P,NXTLNG
	 JRST F1DON	;FINISHED COPY OF FILE1
	PUSHJ P,OUTLIN
	JRST MRGCP1	;CONTINUE

TOEOF1:	SETOM ORGEND
	MOVEI CHAN,1
	TRZ FL,F.LSTLN!F.NLST
MRGCP2:	PUSHJ P,NXTLNG
	 JRST OUTCLS	;DONE
	PUSHJ P,OUTLIN
	JRST MRGCP2

MRGNXT:	HRRZ T5,(T5)
	JUMPE T5,TOEOF1	;FINISH COPY
	JRST MRGLP

NEDFIL:	OUTSTR [ASCIZ /
OUTPUT FILE NAME REQUIRED
/]
	TRNN FL,F.RDTM
	JRST CMDLP
	JRST DEATH

MRGABT:	RENAME FSTCHN+1,FILNAM	;REN PRIMARY EDIT AS MERGE DEST
	 JFCL
	JRST CMDLP
F1DON:	MOVE T1,1(T5)	;GET FILE USE BACK
	CAIN T1,3
	JRST F1DCON	;CONFLICT
	MOVE T4,4(T5)	;USE SECONDARY, GET POINTER
	HRRZ T1,5(T4)	;LINE NUMBER
	SUB T1,2(T4)
	HRRZM T1,SNL#	;THIS WILL BE RESET IF SECONDARY PAGED
	SKIPN T1,1(T4)	;ARE THERE SEQ NUMBERS
	TLZA FL,F.SSEQ
	TLO FL,F.SSEQ
	MOVE T1,OUTPAG
	MOVEM T1,PAGNUM+2	;SET CURRENT PAGE NUMBER
	MOVE T1,3(T4)
	MOVEM T1,ORGEND
	SKIPGE ORG,(T4)
	JRST OUTCLS	;TO EOF, MUST BE DONE
	MOVEI CHAN,2
	PUSHJ P,SETLIN	;SET INPUT POSITION
	PUSHJ P,SETSEQ	;SET RESEQ FLAGS AND PARAMS
	TRZ FL,F.LSTL!F.NLST
MRGIN1:	PUSHJ P,NXTLNG
	 JRST F1COM	;DONE
	PUSHJ P,OUTLIN
	JRST MRGIN1

F1COM:	MOVE T1,PAGNUM+2
	CAMN T1,OUTPAG		;POSSIBLE PAGE MARK AT END
F3COM:	TLNE FL,F.LPG
	PUSHJ P,GENPAG	;NEEDED PAGE AT END
	TLZ FL,F.LPG!F.SMOD!F.SGEN
	MOVEI CHAN,1
	MOVE T4,3(T5)	;NOW SET UP TO FINISH FILE1
	SKIPGE ORG,3(T4)
	JRST OUTCLS	;EOF, DONE
	PUSHJ P,SETLIN
	MOVE T1,OUTPAG
	MOVEM T1,PAGNUM+1
	MOVE T5,(T5)	;LINK
	JUMPN T5,MRGLP
	JRST TOEOF1	;COPY TO EOF
F1DCON:	MOVSI CHAN,-3
	TRZ FL,F.BLIN!F.COM!F.MULT	;WANT ALL THE LINES
CRSRDL:	MOVE T4,2(T5)	;POINT AT CORRECT FILE
	SETZM CRSLNS(CHAN)
	SKIPGE ORG,(T4)
	JRST CRSEOF	;MUST BE EOF TO EOF
	PUSHJ P,SETLIN
	MOVE T1,3(T4)
	MOVEM T1,ORGEND	;WHERE TO STOP
CRSRD1:	AOS T1,CRSLNS(CHAN)
	PUSHJ P,FNDLIN
	 JRST CRSEOF
	MOVE T1,3(T2)
	CAME T1,ORGEND	;IS IT THE LAST LINE?
	JRST CRSRD1	;NO LOOP
CRSEOF:	ADDI T5,1
	SOS CRSLNS(CHAN)	;DO NOT COUNT THE LAST ONE
	AOBJN CHAN,CRSRDL
	SUBI T5,3	;GET T5 POINTED BACK CORRECTLY
	OUTSTR [ASCIZ /
CONFLICT /]
	AOS T1,CFONUM
	PUSHJ P,OUTDEC
	OUTSTR [ASCIZ / REQUIRES RESOLUTION
/]
	SETZM CONHED#	;HERE IS THE LIST OF LINES TO USE
	TRZ FL,F.RDTM
	MOVEI T1,CONHED
	MOVEM T1,CONEND#
	SETZM SNL
	TRO FL,F.SWTC	;SO WE STOP AFTER A COMMAND
	PUSH P,T5	;SAVE CONFLICT POINTER
CNFCMD:	OUTCHR ["*"]
	MOVE T5,[-CNFLEN,,CNFNAM]
	PUSHJ P,TXTSRC
	 JRST	[PUSHJ P,WTLF	;NOTHING THERE
		JRST CNFCMD]
	 JRST ILLCNF
	SUBI T5,CNFNAM
	XCT CNFDSP(T5)

ILLCNF:	PUSHJ P,WTLF
	OUTSTR [ASCIZ /TYPE HELP FOR HELP
/]
	JRST CNFCMD
	DEFINE COMANDS
<	X HELP,<JRST CRSHLP>
	X PRINT,<JRST CRSPRN>
	X GO,<JRST CRSGO>
	X PRIMARY,<JRST CRSPRI>
	X SECONDARY,<JRST CRSSEC>
	X MASTER,<JRST CRSMST>
	X EXAMINE,<JRST CRSEXM>
	X CLEAR,<JRST CRSCLR>
	X ABORT,<JRST ABTMRG>
>

	MAKCMD (CNF)

CRSHLP:	PUSHJ P,WTLF
	OUTSTR CRSHMS
	JRST CNFCMD

CRSHMS:	ASCIZ /COMMANDS ARE:
HELP		PRINTS THIS MESSAGE

PRINT		PRINT THE CONFLICT SOURCE LINES

MASTER		FOLLOWED BY <NUMBER> OR <NUMBER>:<NUMBER>
		SELECTS THE INDICATED LINES TO BE TAKEN FROM THE
		MASTER FILE AND OUTPUT TO THE MERGE FILE. ACTUAL
		OUTPUT TAKES PLACE WHEN THE GO COMMAND IS GIVEN.

PRIMARY		SAME AS MASTER BUT SELECTS LINES FROM THE
		PRIMARY EDIT FILE

SECONDARY	SAME AS MASTER BUT SELECTS LINES FROM THE
		SECONDARY EDIT FILE

EXAMINE		PRINTS THOSE LINES WHICH HAVE BEEN SELECTED SO
		FAR FOR OUTPUT TO THE MERGE FILE

CLEAR		RESETS THE LIST OF LINES SELECTED FOR OUTPUT

GO		TERMINATES THE CONFLICT RESOLUTION AND OUTPUTS
		THE SELECTED LINES TO THE MERGE FILE
/
CRSPRN:	PUSHJ P,WTLF
	SOS CFONUM	;;CNFPRT WILL INCREMENT
	MOVE T5,(P)	;PICK UP THE CONFLICT POINTER
	SETOM TTYFLG
	PUSHJ P,CNFPRT
	SETZM TTYFLG
	JRST CNFCMD

CRSSEC:	MOVEI CHAN,2
	JRST CRSFIL

CRSMST:	TDZA CHAN,CHAN
CRSPRI:	MOVEI CHAN,1
CRSFIL:	PUSHJ P,SKPSP1	;LOOK FOR NUMBER
	PUSHJ P,RDNUM
	JUMPLE T1,CRSBDN	;0 IS BAD
	CAMLE T1,CRSLNS(CHAN)	;TOO LARGE
	JRST CRSBDN
	MOVEM T1,CRSNM1#
	MOVEM T1,CRSNM2#
	PUSHJ P,SKPSP1
	CAIE C,":"
	JRST SNGNUM	;ONLY 1 NUMBER
	PUSHJ P,SKPSP
	PUSHJ P,RDNUM
	JUMPLE T1,CRSBDN
	CAMLE T1,CRSLNS(CHAN)
	JRST CRSBDN
	CAMGE T1,CRSNM1
	JRST CRSBDN
	MOVEM T1,CRSNM2
SNGNUM:	PUSHJ P,WTLF
	PUSHJ P,GETCOR	;GET CORE BLOCK FOR LIST
	SETZM (T2)
	HRRM T2,@CONEND
	HRRZM T2,CONEND	;LINK IN
	HRRZM CHAN,1(T2)	;SAVE SOURCE
	MOVE T1,CRSNM1
	MOVEM T1,2(T2)	;AND START NUMBER
	AOS T3,CRSNM2
	SUB T3,T1	;AND NUMBER OF LINES
	MOVEM T3,3(T2)
	ADDM T3,SNL	;INCREASE NUMBER OF LINES
	JRST CNFCMD

CRSBDN:	PUSHJ P,WTLF
	OUTSTR [ASCIZ /ILLEGAL LINE NUMBER
/]
	JRST CNFCMD
CRSCLR:	PUSHJ P,WTLF
	PUSHJ P,CRSCL1	;RESET CORE LIST
	JRST CNFCMD

CRSCL1:	SETZM SNL	;NO LINES
	MOVE T1,FRECOR
	HRRM T1,@CONEND	;LINK LIST BACK TO FRECORE
	MOVEI T1,0
	EXCH T1,CONHED
	MOVEM T1,FRECOR
	MOVEI T1,CONHED
	MOVEM T1,CONEND
	POPJ P,

CRSEXM:	PUSHJ P,WTLF
	SKIPN T5,CONHED
	JRST CNFCMD	;THERE IS NOTHING THERE
	SETOM TTYFLG	;FORCE OUTPUT TO TTY
CRSXL0:	HRRZ CHAN,1(T5)
	MOVE T1,2(T5)
	PUSHJ P,FNDLIN
	 JRST PRGERR
	MOVE ORG,3(T2)
	PUSHJ P,SETLIN
	MOVE T1,3(T5)	;NUMBER OF LINES
	MOVEM T1,CRSNUM#
	SETOM ORGEND
	TRZ FL,F.LSTL!F.NLST
CRSXL1:	PUSHJ P,NXTLNG
	 JRST PRGERR	;IT WAS THERE BEFORE
	PUSHJ P,CNFPR3	;PRINT WITHOUT LINE NUMBER
	SOSLE CRSNUM
	JRST CRSXL1	;PRINT NUMBER SPECIFIED
	HRRZ T5,(T5)
	JUMPN T5,CRSXL0
	SETZM TTYFLG	;RESET FLAG
	JRST CNFCMD

ABTMRG:	PUSHJ P,WTLF
	TRNN FL,F.TMOP	;MUST BE A TEMP FILE
	JRST ILLCNF	;ELSE BAD COMMAND
	TRO FL,F.ABRT!F.RDTM
	TRZ FL,F.SWTC
	CLOSE OUTCHN,40	;GET RID OF OUTPUT FILE
	RELEASE OUTCHN,
	POP P,T5
	HLLZS FILNAM+3		;SO CORRECT DATE
	JRST MRGABT		;GO DO THE RENAME
CRSGO:	PUSHJ P,WTLF
	TRNE FL,F.TMOP
	TRO FL,F.RDTM	;START READING COMMAND FILE AGAIN
	SKIPN T5,CONHED
	JRST CRSGO1	;NO LINES TO OUTPUT
	TLZ FL,F.SSEQ	;SET NOT SEQUENCED (SNL SET)
	EXCH T5,(P)	;GET CONFLICT POINTER BACK
	PUSHJ P,SETSEQ
	EXCH T5,(P)
CRSGO3:	HRRZ CHAN,1(T5)
	MOVE T1,3(T5)
	MOVEM T1,CRSNUM
	MOVE T1,2(T5)	;MUCH LIKE EXAMINE ABOVE
	PUSHJ P,FNDLIN
	 JRST PRGERR
	MOVE ORG,3(T2)
	PUSHJ P,SETLIN
	SETOM ORGEND
	TRZ FL,F.LSTL!F.NLST
CRSGO2:	PUSHJ P,NXTLNG
	 JRST PRGERR
	PUSHJ P,OUTLIN
	SOSLE CRSNUM
	JRST CRSGO2
	HRRZ T5,(T5)
	JUMPN T5,CRSGO3	;FOR ALL LINES IN LIST
CRSGO1:	PUSHJ P,CRSCL1	;GIVE BACK CORE
	MOVSI CHAN,-3
CRSGO4:	SKIPE T1,NUMLNS(CHAN)	;IN CASE OF EOF
	PUSHJ P,DMPLIN	;GET RID OF LIST
	AOBJN CHAN,CRSGO4
	TRZ FL,F.SWTC	;RESET SWITCH FLAG FOR COMMANDS
	POP P,T5	;RESTORE CONFLICT POINTER
	JRST F3COM
;THIS ROUTINE SETS UP THE INFORMATION NECESSARY TO PUT OUT A LINE
;SET. IT SETS INC, INC2, LSTPAG, F.LPG, ETC
;ON CALL F.SSEQ (SECONDARY SEQUENCED) AND SNL (NUMBER OF LINES)
;ARE ASSUMED SET

SETSEQ:	TLZ FL,F.PPAG!F.SGEN!F.SMOD!F.LPG
	TLNN FL,F.SEQ	;SHOULD OUTPUT BE SEQUENCED?
	POPJ P,		;NO, FORGET ABOUT SETTING PARAMETERS
	SETZM LSTPAG#	;NO LAST PAGE YET
	MOVE T1,LNMOUT	;LAST NUMBER OUTPUT
	MOVEM T1,PS1#	;CALL IT PRIMARY SEQUENCE 1
	MOVE T4,3(T5)	;GET POINTER TO BLOCK FOR PRIMARY FILE
	MOVE T1,4(T4)	;THE LINE NUMBER WORD
	HRRZM T1,PS2#	;SET FIRST LINE NUMBER AFTER MATCH
	HLRZS T1	;GET PAGE NUMBER
	HLRZ T2,1(T4)	;GET PAGE NUMBER OF FIRST LINE
	CAMN T1,T2	;IS THERE A PAGE MARK THERE?
	JRST SSQPNP	;NO, PRIMARY NOT PAGED
	MOVEI T1,↑D100000
	MOVEM T1,PS2	;SET FAKE SECOND SEQUENCE
	SKIPL 3(T4)	;CHECK FOR EOF
	TLO FL,F.PPAG	;IF NOT SAY PRIMARY PAGED
SSQPNP:	TLNE FL,F.SSEQ	;IS SECONDARY FILE SEQUENCED?
	JRST SSQSSQ	;YES
	TLO FL,F.SGEN	;IF NO, MUST GENERATE SEQ NUMBERS
SSQA:	MOVE T1,PS2
	SUB T1,PS1
	MOVE T2,SNL
	IDIVI T1,1(T2)
	CAILE T1,↑D100	;SET INC=MAX(1,MIN(100,(PS2-PS1)/(SNL+1)))
	MOVEI T1,↑D100
	SKIPG T1
	MOVEI T1,1
	MOVEM T1,INC#
SSQB:	TLNE FL,F.PPAG	;IF PRIMARY PAGED
	TLO FL,F.LPG	;SET TO PUT A PAGE MARK AT END
	POPJ P,
;HERE IF SECONDARY ALSO SEQUENCED

SSQSSQ:	MOVE T4,4(T5)	;GET POINTER TO SECONDARY INFO
	MOVE T1,1(T4)
	HRRZM T1,SS1#	;CALL STARTING LINE NUMBER SS1
	MOVE T2,4(T4)
	HRRZM T2,SS2#	;AND ENDING SS2
	HLRZS T1
	HLRZS T2
	CAMN T1,T2	;IS THERE A PAGE MARK PRESENT?
	JRST SSQSNP	;NO
	SUB T2,T1	;GET DIFFERENCE IN PAGES
	MOVE T1,5(T4)	;GET REAL LINE NUMBER OF LAST LINE
	HRRZM T1,SNL2#	;AND SET AS NUMBER ON LAST PAGE
	MOVE T1,5(T5)	;NOW GET NUMBER ON FIRST PAGE
	MOVEM T1,SNL
	SETZM INC2#	;IN CASE WE DO NOT NEED IT
	ADD T2,OUTPAG	;SEE WHAT THE NUMBER OF THE LAST ONE WILL BE
	MOVEM T2,LSTPAG
	MOVE T1,PS2
	CAMLE T1,SS2
	JRST SSQNI2	;WE CAN JUST USE THE OLD NUMS ON LAST PAGE
	MOVE T2,SNL2
	IDIVI T1,1(T2)
	CAILE T1,↑D100
	MOVEI T1,↑D100	;THIS IS LIKE SETTING INC1 ABOVE
	SKIPG T1
	MOVEI T1,1
	MOVEM T1,INC2
SSQNI2:	MOVE T1,PS1
	CAMGE T1,SS1	;DO WE HAVE TO RENUMBER ON THE FIRST PAGE
	JRST SSQB	;NO, SET POSSIBLE ENDING PAGE
SSQC:	TLO FL,F.SMOD	;YES, RENUMBER OF FIRST PAGE
	JRST SSQA

SSQSNP:	MOVE T1,PS1	;NO PAGES IN SECONDARY
	MOVE T2,PS2
	CAMGE T1,SS1
	CAMGE T2,SS2
	JRST SSQC	;WE HAVE TO MODIFY NUMBERS
	JRST SSQB	;DO NOT HAVE TO MODIFY NUMBERS
OUTLIN:	TLNE FL,F.SEQ	;SEQUENCED?
	JRST OUTSEQ	;YES
OUTL1:	PUSHJ P,OCHR
	CAIN C,12
	POPJ P,
	PUSHJ P,GNCH2
	 JRST BADFIL
	JRST OUTL1

OUTSEQ:	TLNN FL,F.SGEN
	JRST SEQNGN	;NOT GENERATING
SEQMOD:	PUSHJ P,OPDSEQ	;GENERATE NEXT LINE NUMBER
SEQGO:	PUSHJ P,GENSEQ	;GENERATE SEQUENCE NUMBER
	PUSHJ P,CPYLBF	;COPY TO LINE BUFFER
DMPLBF:	HRRZ T2,T3	;GET LINE BUFFER POINTER
	SUBI T2,LINBUF-1
	IMULI T2,5	;NUMBER OF CHRS
	MOVE T1,[POINT 7,LINBUF]
DMPLBC:	CAML T2,OBUF+2
	OUTPUT OUTCHN,0
	PUSH P,T2
	MOVEI T2,5
	PUSHJ P,DMPLB1	;PUT OUT THE SEQUENCE NUMBER
	MOVEI T2,1
	IORM T2,@OBUF+1
	POP P,T2
	SUBI T2,5
DMPLB1:	ILDB C,T1
	PUSHJ P,OCHR
	SOJG T2,DMPLB1
	POPJ P,

OPDSEQ:	MOVE T1,INC
	ADDB T1,LNMOUT
	CAIL T1,↑D100000
	SETZM LNMOUT		;JUST SET TO 0 IF EXCEEDS 5 DIGITS
	POPJ P,		;OK
GENSEQ:	MOVE T1,LNMOUT
	CAMLE T1,LNROUT	;WILL THIS BE ORDER ERROR?
	JRST GENSQ2	;NO
	OUTSTR [ASCIZ /
ORDER ERROR ON PAGE /]
	MOVE T1,OUTPAG
	PUSHJ P,OUTDEC
	OUTSTR [ASCIZ /
/]
	MOVE T1,LNMOUT
GENSQ2:	MOVEM T1,LNROUT	;SAVE LAST LINE REALLY OUTPUT
	MOVE T3,[POINT 7,LINBUF]
	MOVSI T4,-5	;GET READY TO DEPOSIT
GENSQ1:	IDIV T1,DECTAB(T4)
	ADDI T1,"0"
	IDPB T1,T3
	MOVE T1,T2
	AOBJN T4,GENSQ1
	POPJ P,

DECTAB:	DEC 10000,1000,100,10,1

CPYLBF:	MOVEI T2,LBFLEN*5-1
	SETZM LINBUF+1
	MOVE T1,[LINBUF+1,,LINBUF+2]
	BLT T1,LINBUF+LBFLEN
	MOVEI T1,11
	IDPB T1,T3
CPYLB1:	IDPB C,T3
	CAIN C,12
	POPJ P,
	PUSHJ P,GNCH2
	 JRST BADFIL
	SOJG T2,CPYLB1
	OUTSTR [ASCIZ /
LINE TOO LONG/]
	EXIT

SEQNGN:	MOVE T1,PAGNUM(CHAN)
	CAMN T1,OUTPAG
	JRST SEQPOK	;DO NOT NEED TO GEN PAGE MARKS
	PUSHJ P,GENPAG	;GENERATE A PAGE MARK
	MOVE T1,OUTPAG
	CAMN T1,LSTPAG
	JRST SEQLPG	;IT IS THE LAST PAGE
SEQNNP:	TLZ FL,F.SMOD	;NOT MODIFYING ANYMORE
	JRST SEQNGN

SEQLPG:	SKIPN T1,INC2
	JRST SEQNNP	;DO NOT GEN ON LAST PAGE
	MOVEM T1,INC
	SETZM LNMOUT
	TLO FL,F.SMOD	;START MODIFYING AGAIN
	JRST SEQNGN
SEQPOK:	TLNE FL,F.SMOD
	JRST SEQMOD
	HRRZM LINUM,LNMOUT
	JRST SEQGO

GENPAG:	MOVEI T2,↑D10
	MOVE T1,[POINT 7,PAGMGN]
	AOS OUTPAG
	PUSH P,C
	PUSHJ P,DMPLBC
	SETOM LNROUT	;NO LINE OUPUT ON THIS PAGE, ANY SEQ OK
	POP P,C	;PRESERVE C
	POPJ P,

PAGMGN:	BYTE (7) 40,40,40,40,40,15,15,14,0,0

LBFLEN==↑D40

ARRAY LINBUF[LBFLEN+1]
DIFPRN:	TRNE FL,F.ABRT
	JRST CMDLP		;IGNORE IF ABORTING
	PUSHJ P,OPNOUT
	 JRST CMDLP	;COULD NOT OPEN OUTPUT
	SETZM DIFNUM#	;NUMBER FOUND SO FAR
	SETZM CFONUM	;FOR PRINTING CONFLICTS
	SKIPN T5,CHGLNK
	JRST DIFNON	;NO DIFS
DIFLP:	MOVE T1,1(T5)	;FILE TO USE
	CAIN T1,3
	JRST DIFCON	;CONFLICT
	CAIE T1,2
	JRST DIFNXT	;NEVER 0, 1 IS SAME AS PRIMARY EDIT
	AOS DIFNUM
	SETZM DIFFIL#	;NUMBER OF FILE WE ARE WORKING ON
	MOVE T4,3(T5)
	PUSHJ P,DIFPR1	;PRINT FOR FILE 1
	OSTR [ASCIZ /***
/]
	MOVE T4,4(T5)
	PUSHJ P,DIFPR1
	OSTR [ASCIZ /******
/]
DIFNXT:	HRRZ T5,(T5)	;LINK
	JUMPN T5,DIFLP
	SKIPN DIFNUM
DIFNON:	OSTR [ASCIZ /
NO DIFFERENCES
/]
	JRST OUTCLS

DIFCON:	PUSHJ P,CNFPRT	;PRINT THE CONFLICT INFORMATION
	AOS DIFNUM
	JRST DIFNXT
DIFPR1:	AOS CHAN,DIFFIL
	SKIPGE ORG,(T4)
	JRST DIFEOF	;EOF TO EOF
	PUSHJ P,SETLIN
	HLRZ T1,1(T4)
	MOVEM T1,PAGNUM(CHAN)
	MOVE T1,3(T4)
	MOVEM T1,ORGEND	;END OF INFORMATION
	TRZ FL,F.LSTL	;NOT LAST LINE
	SETZM CFPNUM	;SO PAGE NUMBER PRINTS ON FIRST LINE
	TRO FL,F.NLST	;BUT WANT THE EXTRA LINE
DIFPR2:	PUSHJ P,NXTLNG
	 POPJ P,	;DONE
	ODEC DIFFIL
	OCRI ")"
	PUSHJ P,LINPR
	JRST DIFPR2

DIFEOF:	OSTR [ASCIZ /EOF ON /]
	ODEC DIFFIL
	OSTR [ASCIZ /
/]
	POPJ P,
PRTCON:	TRNN FL,F.ABRT		;NO CONFLICTS IF ABORTING
	SKIPN CNFNUM
	JRST NOCNF
	PUSHJ P,OPNOUT
	 JRST CMDLP	;CAN NOT OPEN OUTPUT MEDIUM
	MOVE T5,CHGLNK
	SETZM CFONUM#	;THE CONFLICT NUMBER
PRTCLP:	MOVE T1,1(T5)
	CAIN T1,3	;IS IT A CONFLICT?
	PUSHJ P,CNFPRT	;YES, PRINT IT
	MOVE T5,(T5)
	JUMPN T5,PRTCLP	;TRY NEXT ONE
OUTCLS:	RELEASE OUTCHN,0
	JRST CMDLP	;ALL DONE, RELEASE OUTPUT AND WAIT FOR CMD

OPNOUT:	SETOM TTYFLG#
	SKIPN FILNAM+2	;WAS A FILE NAME SPECIFIED?
	JRST CPOPJ1	;NO
	SETZM TTYFLG	;YES, PUT OUTPUT THERE
	INIT OUTCHN,0
	SIXBIT /DSK/
	OBUF,,0
	JRST NODSK
	PUSH P,T1
	MOVE T1,FILNAM+2
	MOVEM T1,FILNAM
	MOVE T1,FILNAM+1
	EXCH T1,FILNAM+3
	MOVEM T1,FILNAM+1
	POP P,T1
	HLLZS FILNAM+1	;GET RID OF GARBAGE
	SETZM FILNAM+2
	ENTER OUTCHN,FILNAM
	 SKIPA
	JRST CPOPJ1
	OUTSTR [ASCIZ /
CAN NOT ENTER OUTPUT FILE
/]
	RELEASE OUTCHN,0
	POPJ P,
;PRINT A CONFLICT

CNFPRT:	OSTR [ASCIZ /
CONFLICT /]
	AOS CFONUM	;THIS IS SET BY CALLER
	ODEC CFONUM
	OSTR [ASCIZ /
/]
	MOVSI CHAN,-3
	SKIPA
CNFPR1:	OSTR [ASCIZ /***
/]		;FLAG BETWEEN FILES
	OSTR @FILASK(CHAN)
	OSTR [ASCIZ /
/]
	MOVE T4,2(T5)	;T5 SET BY CALLER
	SKIPGE ORG,(T4)
	JRST CNFEOF	;STARTS AT EOF
	PUSHJ P,SETLIN
	HLRZ T1,1(T4)
	MOVEM T1,PAGNUM(CHAN)
	MOVE T1,3(T4)
	MOVEM T1,ORGEND#
	SETZM CFLNUM#	;LINE NUMBER
	SETZM CFPNUM#	;PAGE NUMBER WE ARE ON
	TRZ FL,F.LSTL	;NOT LAST LINE
	TRO FL,F.NLST	;BUT WANT THE EXTRA LINE
CNFLCP:	PUSHJ P,NXTLNG
	 JRST CNFPR2	;END OF INFORMATION
	AOS CFLNUM
	ODEC 3,CFLNUM
	OCRI ")"
	PUSHJ P,LINPR
	JRST CNFLCP	;AND LOOP

CNFPR2:	ADDI T5,1
	AOBJN CHAN,CNFPR1
	SUBI T5,3	;GET T5 POINTED BACK CORRECTLY
	OSTR [ASCIZ /******
/]
	POPJ P,

CNFEOF:	OSTR [ASCIZ /END OF FILE
/]
	JRST CNFPR2
;GET THE NEXT LINE. NON-SKIP RETURN IF NO NEXT LINE

NXTLNG:	SETZB LINUM,ORG
	TRNN FL,F.LSTL	;IS IT THE LAST LINE (LAST TIME)
	PUSHJ P,GNCH2
	 POPJ P,		;EOF ON INPUT FILE
	SKIPN LINUM
	PUSHJ P,CLCORG
	CAME ORG,ORGEND
	JRST CPOPJ1	;NOT TO END YET
	TRO FL,F.LSTL	;ON LAST LINE
	TRNE FL,F.NLST	;NEED IT?
	AOS (P)		;YES
	POPJ P,		;NO

;COPY ONE LINE TO OUTPUT, C ALREADY SET

LINPR:	JUMPE LINUM,CNFLNN	;NO LINE NUMBER
	HLRZ T1,LINUM
	CAMN T1,CFPNUM	;HAS PAGE CHANGED?
	JRST CNFLNP	;NO
	MOVEM T1,CFPNUM	;YES
	ODEC CFPNUM	;PRINT IT
CNFLNP:	OCRI 11
	HRRZM LINUM,CNFLNM#
	ODECF 5,CNFLNM	;PRINT LINE NUMBER
CNFLNN:	OCRI 11
CNFPR3:	OCRI (C)
	CAIN C,12
	POPJ P,		;END OF LINE, TRY NEXT LINE
	PUSHJ P,GNCH2
	 JRST BADFIL
	JRST CNFPR3
OUTDEC:	IDIVI T1,↑D10
	HRLM T2,(P)
	SKIPE T1
	PUSHJ P,OUTDEC
	HLRZ T1,(P)
	ADDI T1,"0"
	OUTCHR T1
	POPJ P,

ARRAY SAVAC[20],UUOPDL[40]

UUOH:	0
	MOVEM 17,SAVAC+17	;HERE TO HANDLE THE OUTPUT UUOS
	MOVEI 17,SAVAC
	BLT 17,SAVAC+16
	MOVE P,[IOWD 40,UUOPDL]
	LDB T1,[POINT 9,40,8]
	CAILE T1,UUONUM
	JRST PRGERR
	PUSHJ P,@UUODSP(T1)
	MOVSI 17,SAVAC
	BLT 17,17
	JRSTF @UUOH

UUODSP:	PRGERR
	UUODEC	;OUTPUT DECIMAL NUMBER
	UUODCF	;OUTPUT DECIMAL NUMBER WITH 0 FILL
	UUOCRI	;OUTPUT CHR IMEDIATE
	UUOSTR	;OUTPUT STRING
UUONUM==.-UUODSP

UUOSTR:	HRRZ T2,40	;PICK UP ARG
	HRLI T2,(POINT 7,0)	;TO BYTE POINTER
UUOST1:	ILDB C,T2
	JUMPE C,CPOPJ
	PUSHJ P,OCHR
	JRST UUOST1

UUOCRI:	HRRZ C,40	;GET CHR
OCHR:	SKIPE TTYFLG
	JRST	[OUTCHR C
		POPJ P,]
	SOSG OBUF+2
	OUTPUT OUTCHN,0
	IDPB C,OBUF+1
	POPJ P,
UUODCF:	MOVEI C,"0"
	JRST UUODC0	;SET FILL CHARACTER

UUODEC:	MOVEI C," "
UUODC0:	LDB T3,[POINT 4,40,12]	;GET AC FILED TO DETERMINE SIZE
	HRRZ T1,@40	;AND NUMBER
UUODC1:	IDIVI T1,↑D10
	HRLM T2,(P)
	SUBI T3,1
	SKIPE T1
	PUSHJ P,UUODC1
	JUMPLE T3,UUODC2	;ANY FILL NEEDED?
	PUSHJ P,OCHR	;YES, FILL CHR IS IN C
	SOJG T3,.-1
UUODC2:	HLRZ C,(P)
	ADDI C,"0"
	JRST OCHR
;GENERATE LIST POINTERS FOR A CHANEL

GENCHN:	PUSHJ P,GETCOR
	SETZM (T2)	;NO LINK
	MOVE T4,T2
	MOVE T1,MPOS(CHAN)
	PUSHJ P,FNDLIN	;LAST LINE
	 JRST PRGERR
	MOVE T1,3(T2)	;ORG
	MOVEM T1,3(T4)
	MOVE T1,4(T2)
	MOVEM T1,4(T4)	;LINE NUMBER AND PAGE NUMBER
	MOVE T1,5(T2)
	MOVEM T1,5(T4)	;PHYSICAL LINE NUMBER
	MOVEI T1,1
	PUSHJ P,FNDLIN	;FIRST LINE
	 JRST PRGERR
	MOVE T1,3(T2)	;ORG
	MOVEM T1,(T4)
	MOVE T1,4(T2)
	MOVEM T1,1(T4)
	MOVE T1,5(T2)
	MOVEM T1,2(T4)
	HRRZ T1,CHAN
	CAIE T1,2
	POPJ P,		;NOT CHANEL 2
	SETZM PAGE1#
	SKIPN T1,1(T4)
	POPJ P,		;NOT LINE NUMBERED
	HLRZM T1,PAGFLG#	;SAVE PAGE NUMBER
	HLRZ T1,4(T4)
	CAMN T1,PAGFLG
	POPJ P,		;NO PAGE MARK
	MOVEI T1,1
	MOVEM T1,USEFLG#
PGELP:	AOS T1,USEFLG	;FIND FIRST BLOCK OF DIFFERENT PAGE
	PUSHJ P,FNDLIN
	 JRST PRGERR
	HLRZ T1,4(T2)
	CAMN T1,PAGFLG
	JRST PGELP	;CONTINUE
	HLRZ T1,5(T2)	;GET PHYSICAL LINE NUMBER
	MOVEM T1,PAGE1
	POPJ P,
INRLN1:	AOBJN T4,INRLP
NXTINR:	ADDI T5,2
	AOBJN T5,INRC	;TRY NEXT WAY OF MATCHING CHANNELS
	JRST NMTCH0	;GET MORE LINES AND TRY

INRLN2:	AOBJN T4,INRLP2	;TRY NEXT LINE
	POP P,T4
	SKIPN INFLG	;WAS A MATCH SEEN ANYWHERE ON FILE 3
	JRST NXTINR	;NO, FORGET IT
	MOVE CHAN,CHANTB+1(T5)	;RSET AND TRY OTHER CHANNEL
	JRST INRLN1


TRIABT:	POP P,T4
	MOVE CHAN,CHANTB+2(T5)
	JRST INRLN2	;ABORT AND TRY OTHER CHANNEL

CHNPTR:	CHANTB(T5)
	CHANTB+1(T5)
	CHANTB+2(T5)

EOFTB2:	JRST M3EOF1
	SOS MPOS(CHAN)
	SOS MPOS(CHAN)

EOFTB3:	JRST TRIEF1
	JRST TRIABT
	JRST TRIABT

LIMMTC:	DMOVEM HASH,SHS1
	JFCL
	JFCL

CHANTB:	EXP 1,0,2,2,1,0,0,2,1

TRIEF2:	MOVE CHAN,@CHNPTR(T4)	;EOF ON SOME FILES
	AOS T1,MPSP(T4)
	PUSHJ P,FNDLIN
	 SKIPA		;EOF THERE ALSO
	JRST TRIABT	;NOT EOF ON ALL
TRIEF1:	AOBJN T4,TRIEF2
	JRST MTCFND	;EOF ON ALL, CALL IT A MATCH

M3EOF1:	SOS MPOS(CHAN)	;1 FEWER LINES THAT CHAN
	AOBJP CHAN,ALLEOF	;IF OUT OF CHANNELS, ALL HAD EOF
	AOS T1,MPOS(CHAN)
	PUSHJ P,FNDLIN
	 JRST M3EOF1	;LOOK FOR A LINE ON OTHERS
	JRST NMTCH2	;FOUND AT LEAST 1 WITHOUT EOF
;POSITION TO A LINE USING ORG

SETLIN:	HRRZ BUF,BUFORG(CHAN)
	SETZM EOF(CHAN)	;NOT AT EOF ANYMORE
	HRRZ T1,ORG	;GET BLOCK NUMBER
	CAMN T1,BLOCKN(CHAN)	;AND COMPARE WITH CURRENT
	JRST SAMBLK	;MUST BACKUP (OR MAYBE SAME)
	XCT USI(CHAN)	;SET TO CORRECT BLOCK
	XCT INP(CHAN)	;AND READ BLOCK
	AOS 2(BUF)	;TO COMPENSATE FOR READ BEFORE SOS
	HRRZM ORG,BLOCKN(CHAN)
SAMBLK:	HLRZ T1,ORG
	ADDI T1,1	;SINCE SOS NOT DONE YET
	EXCH T1,2(BUF)
	SUB T1,2(BUF)	;NOW SET COUNT CORRECT AND GET DIFF
	JUMPE T1,CPOPJ	;IF NO DIFF, DONE
	IDIVI T1,5
	JUMPGE T2,ADVBYP	;IF POS OR 0 REM, GO
	ADDI T2,5	;MAKE IT POS
	SUBI T1,1	;AND BACK UP 1 MORE WORD
ADVBYP:	ADDM T1,1(BUF)
	SKIPA
	IBP 1(BUF)
	SOJGE T2,.-1	;GET BYTE POINTER TO CORRECT SPOT
	POPJ P,

TYPLIN:	PUSHJ P,LINCHR	;GET CHR FROM LINE
	OUTCHR C
	CAIE C,12
	JRST TYPLIN
	POPJ P,

LINCHR:	SOSLE 2(BUF)
	JRST LINCH1
	XCT INP(CHAN)
	AOS BLOCKN(CHAN)
	XCT EOFTST(CHAN)
	JRST LINCH1
	JRST BADFIL	;SHOULD NOT BE EOF THERE

LINCH1:	ILDB C,1(BUF)
	POPJ P,
;FIND A LINE IN THE LINE TABLE LIST. NUMBER IN T1

FNDLIN:	CAMG T1,NUMLNS(CHAN)
	JRST FNDOLN	;LINE IS IN THE LIST
	SUB T1,NUMLNS(CHAN)
	MOVEM T1,XTRLNS#	;NUMBER OF EXTRA LINES TO READ
FNDLN1:	PUSHJ P,GETLNF
	 POPJ P,	;EOF
	PUSHJ P,ADDLST	;ADD LINE TO LIST
	SOSLE XTRLNS
	JRST FNDLN1	;NEED MORE
	JRST CPOPJ1	;GOT IT (ORG, LINUM, HASH, HASH1 SET)

FNDOLN:	MOVE T2,LNKHED(CHAN)
	JUMPE T2,PRGERR	;NOT REALLY IN LIST, ERROR
	SOJLE T1,FNDOL1	;IS THIS THE POINTER (ORIGINALL TO 1)
	HRRZ T2,(T2)	;NO, CHAIN
	JUMPN T2,.-2
PRGERR:	OUTSTR [ASCIZ /
PROGRAM ERROR/]
	EXIT

FNDOL1:	DMOVE HASH,1(T2)	;RELOAD REGISTERS
	JRST CPOPJ1

;ADD A LINE TO THE LINKED LIST OF LINES

GETCOR:	SKIPE T2,FRECOR
	JRST	[HRRZ T3,(T2)
		MOVEM T3,FRECOR	;RELINK FREE LIST
		POPJ P,]
	MOVE T2,JOBFF
	ADDI T2,BLKSIZ
	CAMG T2,JOBREL
	JRST GOTC1	;IS IN ACTUAL CORE, OK
	IORI T2,1777
	CORE T2,
	 JRST CORERR	;CAN NOT GET CORE
GOTC1:	MOVEI T2,BLKSIZ
	EXCH T2,JOBFF
	ADDM T2,JOBFF	;UPDATE JOBFF AND SET T2
	POPJ P,

ADDLST:	PUSHJ P,GETCOR
	HRRM T2,@LNKEND(CHAN)	;LINK IT IN
	HRRZM T2,LNKEND(CHAN)	;AND RESET END POINTER
	SETZM (T2)	;NOT LINKED
	DMOVEM HASH,1(T2)
	MOVEM ORG,3(T2)
	MOVEM LINUM,4(T2)
	MOVEM LNS1,5(T2)
	AOS NUMLNS(CHAN)
	POPJ P,		;STORE INFO AND RECORD 1 MORE LINE IN LIST
;REMOVE A LINE BLOCK FROM LIST AND PUT ON FREE CORE
;T1 HAS NUMBER OF LINES TO REMOVE

DMPLIN:	SKIPN T2,LNKHED(CHAN)
	JRST PRGERR
DMPLP:	HRRZ T3,(T2)	;GET NEXT POINTER
	SOS NUMLNS(CHAN)
	SOJLE T1,DMPLP2	;FINISHED WHEN COUNT RUNS OUT
	MOVE T2,T3
	JUMPN T2,DMPLP
	JRST PRGERR

DMPLP2:	EXCH T3,LNKHED(CHAN)	;RELINK CHANNEL LIST
	EXCH T3,FRECOR		;PUT OLD HEAD ON FREE LIST
	HRRZM T3,(T2)		;AND RELINK OLD CHAIN
	SKIPE LNKHED(CHAN)
	POPJ P,
	MOVEI T3,LNKHED(CHAN)
	MOVEM T3,LNKEND(CHAN)	;RESET LNKEND IF ALL GONE
	POPJ P,
RDFLNM:	SETZM FILNAM+1
	SETZM FILNAM+2
	SETZM FILNAM+3
	PUSHJ P,SKPSP	;SKIP SPACES
;;TYM	CAIN C,"("
;;TYM	JRST RDUSRN	;GO READ THE USER NAME
RDFLN1:	MOVE T1,[POINT 6,FILNAM+2]
	MOVEI T2,6
	PUSHJ P,RDTXT1
	PUSHJ P,SKPSP1
	CAIE C,"."	;CHECK EXTENSION
;;SU
	JRST	CHKPPN
;;TYM	JRST CHKSW	;CHECK FOR SWITCHES
	MOVE T1,[POINT 6,FILNAM+3]
	MOVEI T2,3
	PUSHJ P,RDTXT
;;SU
CHKPPN:	CAIE	C,"["
	JRST	CHKSW	;CHECK FOR SWITCHES
	MOVE	T1,[POINT 6,FILNAM+1]
	MOVEI	T2,3
	PUSHJ	P,RDTXT		;PROJ
	SKIPA	T1,FILNAM+1	;RIGHT JUSTIFY SIXBIT IN LEFT HALF OF WORD
	LSH	T1,-6
	TLNN	T1,77
	JRST	.-2
	MOVEM	T1,FILNAM+1
	MOVE	T1,[POINT 6,FILNAM+1,17]
	MOVEI	T2,3
	PUSHJ	P,RDTXT		;PROG
	HRRZ	T1,FILNAM+1	;RIGHT JUSTIFY SIXBIT IN RIGHT HALF OF WORD
	SKIPA
	LSH	T1,-6
	TRNN	T1,77
	JRST	.-2
	HRRM	T1,FILNAM+1
;;SU
WTLF:	CAIN C,12
	POPJ P,
	PUSHJ P,CMDCHR
	JRST WTLF

SKPSP:	PUSHJ P,CMDCHR
SKPSP1:	CAIE C," "
	CAIN C,11
	JRST SKPSP
	POPJ P,

RDTXT:	PUSHJ P,CMDCHR
RDTXT1:	CAIL C,140
	SUBI C,40
	CAIG C,"Z"
	CAIGE C,"0"
	POPJ P,		;NOT TEXT
	CAIGE C,"A"
	CAIG C,"9"
	SKIPA
	POPJ P,		;NOT TEXT
	SOJL T2,RDTXT	;DO NOT PUT IN TOO MANY
	SUBI C,40
	IDPB C,T1
	JRST RDTXT

CHKSW1:	PUSHJ P,SKPSP1
CHKSW:	TRNE FL,F.SWTC	;DO WE WANT SWITCHES
	CAIE C,"/"	;AND IS IT ONE?
	JRST WTLF	;NO TO ONE OF THOSE
	MOVE T5,[-SWTLEN,,SWTNAM]
	PUSHJ P,TXTSRC
	 JRST ILLSW
	 JRST ILLSW
	SUBI T5,SWTNAM
	XCT SWTDSP(T5)
	JRST CHKSW1
	DEFINE COMANDS
<	X BLANKLINES,<TRO FL,F.BLIN>
	X COMMENT,<TRO FL,F.COM>
	X MULTIBLANK,<TRO FL,F.MULT>
	X MATCH,<PUSHJ P,GETMTC>
>

	MAKCMD (SWT)

GETMTC:	PUSHJ P,SKPSP1
	PUSHJ P,RDNUM
	MOVEM T1,XTRMTC
	POPJ P,

RDNUM:	MOVEI T1,0
RDNUM1:	CAIG C,"9"
	CAIGE C,"0"
	POPJ P,		;NOT A DIGIT ANYMORE
	IMULI T1,↑D10
	ADDI T1,-"0"(C)
	PUSHJ P,CMDCHR
	JRST RDNUM1

ILLSW:	PUSHJ P,WTLF
	OUTSTR SWTMSG
	SETZM FILNAM+2
	POPJ P,

SWTMSG:	ASCIZ /
LEGAL SWITCHES ARE:

BLANKLINES	IGNORE BLANK LINES
COMMENT		IGNORE COMMENTS (EVERYTHING ON A LINE AFTER ;)
MULTIBLANK	TREAT TABS AND MULTIPLE BLANKS AS A SINGLE BLANK
MATCH		FOLLOWED BY A NUMBER, SETS NUMBER OF SEQUENTIAL LINES
		WHICH MUST MATCH AFTER THE FIRST MATCH
/
RDUSRN:	MOVE T1,[POINT 6,FILNAM+4]
	MOVEI T2,FILNAM+4
	MOVEM T2,FILNAM+1	;SET POINTER TO USER NAME
	SETZM FILNAM+4
	SETZM FILNAM+5
	MOVEI T2,↑D12	;MAX OF 12 CHRS
	PUSHJ P,SKPSP
	SKIPA
RDUSRL:	PUSHJ P,CMDCHR
	CAIE C,")"
	CAIGE C," "
	JRST RDUSRF	;GO FINISH UP
	CAIL C,140
	SUBI C,40
	SOJL T2,RDUSRL
	SUBI C,40
	IDPB C,T1
	JRST RDUSRL

RDUSRF:	CAIE C,")"
	JRST WTLF	;WILL CAUSE ERROR WITH 0 FILE NAME
	PUSHJ P,SKPSP	;SKIP SPACES AFTER USER NAME
	JRST RDFLN1	;AND GO GET THE FILE NAME
;READ A LINE FROM APPROPRIATE CHANNEL AND RETURN HASH AND ORG
;AND LINE NUMBER (IF PRESENT)

GETLNF:	SKIPE EOF(CHAN)
	POPJ P,		;HAVE REACHED END OF FILE
	SETZB LINUM,ORG
	MOVEI C,GCHORG
	MOVEM C,GCHDSP	;SET UP FOR CALLS TO GET CHR (CO-ROUTINE)
	DMOVE HASH,HSHORG
	MOVE BUF,BUFORG(CHAN)
	PUSHJ P,@GCHDSP
	 POPJ P,	;EOF
	MOVE LNS1,REALN(CHAN)	;GET THE REAL LINE NUMBER
	HRL LNS1,PAGLN(CHAN)	;AND PAGE NUMBER IF APPROP
	SETZM PAGLN(CHAN)	;SO WILL BE SET NEXT TIME
GETLN1:	IMULI HASH,101
	ADD HASH,C
	IMULI HASH1,131
	ADD HASH1,C
	CAIN C,12
	JRST CPOPJ1	;FINISHED WHEN LINE FEED SEEN
	PUSHJ P,@GCHDSP
	 JRST BADFIL	;EOF IN MIDDLE OF LINE
	JRST GETLN1	;PROCESS NEXT CHR

;ROUTINE TO GET ACTUAL CHARACTER OF INPUT
;CHECKS LINE NUMBER AND PAGE MARK

GNCH2:	SKIPE EOF(CHAN)
	POPJ P,		;CHECK FOR EOF FIRST
	MOVE BUF,BUFORG(CHAN)
GNCH1:	SOSLE 2(BUF)
	JRST GNCH3
	XCT INP(CHAN)
	AOS BLOCKN(CHAN)
	XCT EOFTST(CHAN)
	JRST GNCH3	;NOT EOF
	SETOM EOF(CHAN)	;IS EOF, FLAG IT
	POPJ P,

GNCH3:	IBP 1(BUF)
	MOVEI C,1
	TDNE C,@1(BUF)
	JRST GNCLNM	;THIS IS A LINE NUMBER
	LDB C,1(BUF)	;NOT LINE NUMBER
	JUMPE C,GNCH1	;IGNORE NULLS
CPOPJ1:	AOS (P)
CPOPJ:	POPJ P,

HSHORG:	010101010101
	030303030303
GNCLNM:	MOVE LINUM,@1(BUF)
	CAMN LINUM,PGMRK
	JRST GNCPAG	;THIS IS A PAGE MARK, SPECIAL
	PUSHJ P,CNVLNM	;CONVERT LINE NUMBER TO BINARY
	HRL LINUM,PAGNUM(CHAN)	;AND GET PAGE
	MOVEM LINUM,LSTLNC(CHAN)
	PUSHJ P,CLCORG	;SET ORG REGISTER
	PUSHJ P,SKPLNM	;SKIP OVER THE LINE NUMBER
	JRST GNCH1	;AND GET FIRST CHR ON LINE

SKPLNM:	MOVNI C,4
	ADDM C,2(BUF)	;SKIP REMAINING 4 CHRS OF LINE NUMBER
	REPEAT 4,<IBP 1(BUF)>
	PUSHJ P,GNCH1	;SKIP THE TAB (IN CASE IN NEXT BUFFER)
	 JRST BADFIL	;EOF IN MIDDLE OF LINE
	POPJ P,

GNCPAG:	AOS PAGNUM(CHAN)	;ON NEXT PAGE NOW
	MOVEI C,0
	EXCH C,REALN(CHAN)
	SKIPN PAGLN(CHAN)
	MOVEM C,PAGLN(CHAN)	;RESET LINE/PAE COUNT IF PICKED UP
	PUSHJ P,SKPLNM	;SKIP THE PAGE MARK
GNCPG1:	PUSHJ P,GNCH1
	 JRST BADFIL
	CAIE C,14	;NOW WAIT FOR THE FORM FEED
	JRST GNCPG1
	JRST GNCH1

PGMRK:	<ASCII /     />+1

CLCORG:	HRR ORG,BLOCKN(CHAN)
	HRL ORG,2(BUF)
	POPJ P,		;THIS IS ENOUGH TO FIND IT AGAIN

CNVLNM:	PUSH P,LINUM
	MOVEI LINUM,0
	MOVEI T2,5	;5 CHRS
	MOVE T1,[POINT 7,(P)]
CNVLLP:	ILDB C,T1
	IMULI LINUM,↑D10
	ADDI LINUM,-"0"(C)
	SOJG T2,CNVLLP
	POP P,T1
	POPJ P,
;ROUTINE TO GET A CHARACTER AND WORRY ABOUT BLANK LINES
;COMMENTS AND MULTI-BLANKS

GCHORG:	PUSHJ P,GNCH1
	 POPJ P,	;EOF
	SKIPN ORG
	PUSHJ P,CLCORG
	JUMPN LINUM,GCHOR1
	CAIN C,14
	JRST GCHORG
GCHOR1:	AOS REALN(CHAN)
	SETZM RETNUM#	;NO CHRS RETURNED SO FAR
	CAIN C,15
	TRNN FL,F.BLIN
	JRST GCH1	;NOT RETURN OR DO NOT WORRY ABOUT BLANK LINES
GCHWLF:	PUSHJ P,GNCH1
	 JRST BADFIL	;EOF IN MIDDLE OF LINE
	CAIE C,12
	JRST GCHWLF	;WAIT FOR LINE FEED
	JRST GCHORG	;AND GET A REAL LINE

GCH1:	CAIN C,";"
	TRNN FL,F.COM
	JRST GCH2	;NOT ; OR NOT IGNORE COMMENTS
	TRNE FL,F.BLIN
	JRST GCHBLC	;IF ; FIRST ON LINE AND IGNORE BLANK LINES THEN IGNORE
GCHIGC:	MOVEI C,15	;GIVE AND END OF LINE
	JSR GCHDSP	;CO-ROUTINE RETURN
GCHWL1:	PUSHJ P,GNCH1
	 JRST BADFIL
	CAIE C,12
	JRST GCHWL1
	JSR GCHDSP	;RETURN THE LINE FEED
	JRST GCHORG

GCHBLC:	SKIPN RETNUM
	JRST GCHWLF	;NOTHING RETURNED, IGNORE LINE
	JRST GCHIGC	;SOME CHRS RETURNED, GIVE END OF LINE

GCH2:	AOS RETNUM	;WILL RETURN AT LEAST 1
	TRNE FL,F.MULT
	JRST GCHMLT	;WORRY ABOUT MULTI BLANKS
GCH3:	JSR GCHDSP	;RETURN CHR
	PUSHJ P,GNCH1
	 JRST BADFIL
	JRST GCH1

GCHMLT:	CAIE C," "
	CAIN C,11
	SKIPA
	JRST GCH3	;NOT BLANK, RETURN IT
	MOVEI C," "
	JSR GCHDSP	;RETURN A BLANK
GCHML1:	PUSHJ P,GNCH1
	 JRST BADFIL
	CAIE C," "
	CAIN C,11
	JRST GCHML1	;KEEP SKIPPING BLANKS
	JRST GCH1	;NOT BLANK, MIGHT BE ;, GO CHECK

GCHDSP:	0
	JRST CPOPJ1

	END STPT